﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    class Moto
    {
        Texture2D textura;

        Vector2 posicao;

        GameWindow Window;

        /// <summary>
        /// CONSTRUTOR
        /// </summary>
        /// <param name="Content"></param>
        public Moto(ContentManager Content, GameWindow Window, float x, float y)
        {
            this.Window = Window;
            textura = Content.Load<Texture2D>("moto");
            posicao = new Vector2(x, y);
        }

        public void Update(GameTime gametime, KeyboardState teclado, int player)
        {
            if(player == 1){

                if (teclado.IsKeyDown(Keys.Right))
                {
                    posicao.X += 5;
                }
                if (teclado.IsKeyDown(Keys.Left))
                {
                    posicao.X -= 5;
                }
                if (teclado.IsKeyDown(Keys.Up))
                {
                    posicao.Y -= 5;
                }
                if (teclado.IsKeyDown(Keys.Down))
                {
                    posicao.Y += 5;
                }

                if (posicao.X >= Window.ClientBounds.Width - textura.Width)
                {
                    posicao.X = Window.ClientBounds.Width - textura.Width;
                
                }
                if (posicao.X <= 0)
                {
                    posicao.X = 0;
                
                }

                if (posicao.Y >= Window.ClientBounds.Height - textura.Height)
                {
                    posicao.Y = Window.ClientBounds.Height - textura.Height;
               
                }

                if (posicao.Y <= 0)
                {
                    posicao.Y = 0;
                
                }
            }
            else if (player == 2)
            {
                if (teclado.IsKeyDown(Keys.D))
                {
                    posicao.X += 5;
                }
                if (teclado.IsKeyDown(Keys.A))
                {
                    posicao.X -= 5;
                }
                if (teclado.IsKeyDown(Keys.W))
                {
                    posicao.Y -= 5;
                }
                if (teclado.IsKeyDown(Keys.S))
                {
                    posicao.Y += 5;
                }

                if (posicao.X >= Window.ClientBounds.Width - textura.Width)
                {
                    posicao.X = Window.ClientBounds.Width - textura.Width;

                }
                if (posicao.X <= 0)
                {
                    posicao.X = 0;

                }

                if (posicao.Y >= Window.ClientBounds.Height - textura.Height)
                {
                    posicao.Y = Window.ClientBounds.Height - textura.Height;

                }

                if (posicao.Y <= 0)
                {
                    posicao.Y = 0;

                }
            }

        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(textura, posicao, new Color(255, 255, 255));
        }




    }
}
